package com.example.book.crawler;


import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 队列 分类、目标url、页面数
 */
public class BlockingQueues {

    private static BlockingQueue<Map<String, Object>> queue_catalog;
    private static BlockingQueue<Integer> queue_page;
    private final static int pageNum = 1500;

    public static BlockingQueue<Integer> getInstanceForPage() throws InterruptedException {
        if (queue_page ==null){
            synchronized (BlockingQueues.class){
                queue_page = new LinkedBlockingQueue<>();
                for (int i = 1; i <= pageNum; i++) {
                    queue_page.put(i);
                }
            }
        }
        return queue_page;
    }


    public static BlockingQueue<Map<String, Object>> getInstanceForCatalog()  {

        Map<String,Object> map = null;
        if (queue_catalog ==null){
            synchronized (BlockingQueues.class){
                if (queue_catalog  == null){
                    queue_catalog = new LinkedBlockingQueue<>();

                    map = new HashMap<>();
                    map.put("cid","010d3b690cc743139037844c90ccc39a");
                    map.put("url","https://www.wmtxt.net/fenlei1/");
                    queue_catalog.add(map);

                    map = new HashMap<>();
                    map.put("cid","16a3c3e6c9cd4fa29f213e00409c3a89");
                    map.put("url","https://www.wmtxt.net/fenlei2/");
                    queue_catalog.add(map);

                    map = new HashMap<>();
                    map.put("cid","3570432f1a2143adb1f7a296309d4d5a");
                    map.put("url","https://www.wmtxt.net/fenlei3/");
                    queue_catalog.add(map);

                    map = new HashMap<>();
                    map.put("cid","4250094febe245ba8a30696cdc890bbf");
                    map.put("url","https://www.wmtxt.net/fenlei4/");
                    queue_catalog.add(map);

                    map = new HashMap<>();
                    map.put("cid","5252bc68d1984e08aedcc37a5152c114");
                    map.put("url","https://www.wmtxt.net/fenlei5/");
                    queue_catalog.add(map);

                    map = new HashMap<>();
                    map.put("cid","ef508cf8e9fd454c88fa093446d76d52");
                    map.put("url","https://www.wmtxt.net/fenlei6/");
                    queue_catalog.add(map);

                }
            }
        }

        return queue_catalog;
    }

}
